<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header>
      <div>
        <span>教师教学业绩材料管理系统</span>
        <el-dropdown class="user-dropdown">
          <span class="el-dropdown-link">
            {{ loginUserName }}
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </div>
    </el-header>

    <el-container>
      <!-- 侧边栏区域 -->
      <LeftNav></LeftNav>
      <!-- 右侧主体区域 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>

    <!--  新增字典对话框-->
    <el-dialog title="最新公告" :visible.sync="viewDialogVisible" width="50%">
      <el-form label-width="80px">
        <el-form-item label="标题" prop="title">
          <el-input v-model="billboard.title" disabled></el-input>
        </el-form-item>
        <el-form-item label="详情" prop="context">
          <el-input type="textarea" :rows="8" v-model="billboard.context" disabled></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="viewDialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </el-container>
</template>

<script>
// @ is an alias to /src
import LeftNav from '@/components/LeftNav.vue';

export default {
  name: 'Home',
  data() {
    return {
      viewDialogVisible: false,
      billboard: {
        title: '',
        context: ''
      }
    };
  },
  mounted: async function() {
    const { data: resp } = await this.$http.get('billboard/latest');
    if (resp.code === 0) {
      this.billboard = resp.data;
      this.viewDialogVisible = true;
    }
  },
  components: {
    LeftNav
  },
  computed: {
    loginUserName: function() {
      return window.sessionStorage.getItem('login_user_name');
    }
  },
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push('/login');
    }
  }
};
</script>

<style lang="less" scoped>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
  display: flex;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}

.home-container {
  height: 100%;
}

.user-dropdown {
  position: absolute;
  right: 50px;
}
</style>
